﻿using App.Domain.Model;
using System.ComponentModel.DataAnnotations;

namespace App.MVCClient.Models
{
    public class AddressDTO
    {
        public AddressDTO()
        {
            AddressID = -1;
            CountryCode = "IN";
            StateProvinceCode = "WB";
        }
        public AddressDTO(Address model)
            : this()
        {
            AddressID = model.AddressID;
            AddressLine1 = model.AddressLine1;
            AddressLine2 = model.AddressLine2;
            City = model.City;
            StateProvinceCode = model.StateProvince == null ? null : model.StateProvince.StateProvinceCode;
            PostalCode = model.PostalCode;
        }

        public int AddressID { get; set; }

        [Required]
        [Display(Name = "Address Line 1")]
        public string AddressLine1 { get; set; }
        [Display(Name = "Address Line 2")]
        public string AddressLine2 { get; set; }

        [Required]
        [Display(Name = "City")]
        public string City { get; set; }

        [Required]
        [Display(Name = "Country Code")]
        public string CountryCode { get; set; }

        [Required]
        [Display(Name = "State/Province Code")]
        public string StateProvinceCode { get; set; }

        [Required]
        [Display(Name = "Postal Code")]
        public string PostalCode { get; set; }

        public Address GetModel(StateProvince state)
        {
            return new Address(AddressLine1, City, state, PostalCode) { AddressLine2 = AddressLine2 };
        }
    }
}